/**
 * 
 */
package cii_lib_graph.elements;

import java.awt.Component;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author pdrabik
 * 
 */
public class GUIUtils {
	
	private static final Logger log = LoggerFactory.getLogger(GUIUtils.class);

	public static void enableContainer(Container root, boolean enable) {
		Component children[] = root.getComponents();
		for (int i = 0; i < children.length; i++) {
			if (((Container)children[i]).getComponents().length!=0) {
				enableContainer((Container) children[i], enable);
			} else {
				children[i].setEnabled(enable);
			}
		}
		
	}
	
	public static ActionListener createListener(final ActionListener listener) {
		return new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent evt) { 
				log.info("Command: {}", evt.getActionCommand());
				listener.actionPerformed(evt);
			}
		};
	}
}
